import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Index from '../views/Index.vue'
import PlayerShare from '../views/PlayerShare.vue'
import Scheme from '../views/Scheme.vue'
import Off from '../views/offView.vue'
import Code from '../views/HardCore.vue'
import Care from '../views/MeCare.vue'
import store from '../store/index.js'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: Index,
    meta:{
      selected:1
    }
  },
  {
    path: '/PlayerShare',
    name: 'PlayerShare',
    component:PlayerShare,
    meta:{
      selected:2
    }
  },
  {
    path: '/Scheme',
    name: 'Scheme',
    component:Scheme,
    meta:{
      selected:3
    }
  },
  {
    path: '/Off',
    name: 'off',
    component: Off,
    meta:{
      selected:4
    }
  },
  {
    path: '/Code',
    name: 'HardCore',
    component: Code ,
    meta:{
      selected:7,
      CheckName:'硬核'
    }
  },
  {
    path: '/ViewDetail',
    name: 'Detail',
    component: () => import('../views/ViewDetail.vue'),
  },
  {
    path: '/UserFeil',
    name: 'UserFeil',
    component: () => import('../views/UserFeil.vue'),
    redirect:'/UserFeil/replyList',
    children:[
      {
        path: 'replyList',
        name: 'replyList',
        component: () => import('../views/UserFeilSon/replyList.vue'),
        meta:{
          active:1
        }
      },
      {
        path: 'bookList',
        name: 'bookList',
        component: () => import('../views/UserFeilSon/bookList.vue'),
        meta:{
          active:2
        }
      },
      {
        path: 'followList',
        name: 'followList',
        component: () => import('../views/UserFeilSon/followList.vue'),
        meta:{
          active:3
        },
      },
      {
        path: 'edit',
        name: 'edit',
        component: () => import('../views/UserFeilSon/edit.vue'),
        meta:{
          active:4
        }
      },
    ]
  },
  {
    path: '/MeCare',
    name: 'MeCare',
    component: Care ,
    meta:{
      needLogin:1,
      selected:8,
    }
  },
  {
    path: '/search',
    name: 'SearchView',
    component: () => import('../views/SearchView.vue'),
    meta:{
      search:1
    }
  },
  {
    path: '*',
    name: 'NotFound',
    component: () => import('../views/NotFound.vue'),
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this, location).catch(err => err)
  }
router.beforeEach((to,from,next)=>{
  // console.log('to',to,'from',from,store)
  window.scrollTo(0,0)
  if(to.meta.needLogin&&store.state.LoginState.length==0){
    alert('请登录')
    return
  }
  next()
}
)

export default router
